<?php

/**
* @property DB_active_record $db
* @property Service $service
* @property Provider $provider
* */
class MY_Controller extends CI_Controller {
//	var $xAddr = 0;
//	var $yAddr = 0;

	var $data = array();
	var $templateLayout = "_Shared/_Layout"; // default Layout
	var $include_view = ""; // each module layout
	var $controller_name ;
	
	public function __construct()
	{
		parent::__construct();

		$this->load->helper('html');
		$this->load->library('table');
		$this->load->model("base_flexmodel");
//		$this->load->model("service");
//		$this->load->model("provider");
//		$this->load->model("organisation_type");
//		$this->load->model("dgp_zone");
		$this->load->helper('form');
		$this->load->helper('url');
		
		$this->data['include_view'] = "";
		
		$controller_name = $this->router->fetch_class();
		
		//$this->load->helper('captcha');
//		$this->load->library('parser');
//		$data['include_view'] = "bagian.php" ;
//		$this->load->library("searchaddress");
//		$this->load->library("input");
	}
	
	public function set_template ( $templateLayout )
	{
		$this->templateLayout = $templateLayout;
	}
	
	public function add_data ( $name , $value )
	{
		$this->data [ $name ] = $value;
	}
	
	/**
	 * Unified view function, utilizing $this->load->view with Shared Layout <BR/><BR/>
	 * to Automate : <BR/>
	 * &nbsp;&nbsp;&nbsp;&nbsp; $data['include_view'] = "Search/byService.php" ;<BR/>
	 * &nbsp;&nbsp;&nbsp;&nbsp; $this->load->view("_Shared/_Layout" , $data);
	 * @param $p_view String
	 * used as main container in html / module UI
	 * @param $p_templateLayout String
	 * if p_templateLayout null then use default templateLayout as View <BR/>
	 * if p_templateLayout "" then use p_view as View <BR/>
	 * if p_templateLayout "customizedLayout" then use "customizedLayout" as View <BR/>
	 * @param $p_data Array
	 * if $p_data null then use default data <BR/>
	 * to add default data use function add_data instead
	 */
	public function view ( $p_view , $p_templateLayout = null , $p_data = null )
	{
		if ( $p_templateLayout == null ) // use default layout
		{
			$this->data['include_view'] = $p_view ;
			$this->load->view( $this->templateLayout , $this->data);
		}
		else if ( $p_templateLayout == "" ) // not use default layout
		{
			$this->data += $p_data;
			
			if ( $p_data != null )
				$this->load->view( $p_view , $p_data);
			else
				$this->load->view( $p_view , $this->data);
		}
		else // $templateLayout != "" ) // use customized layout
		{
			if ( $p_data != null )
				$this->load->view( $p_templateLayout , $p_data);
			else
				$this->load->view( $p_templateLayout , $this->data);
		}
	}
	
	public function check_null () // return bool
	{
		foreach (func_get_args() as $object )
			if ( $object == null )
				return false;
		return true;
	}
	public function check_null_show_error () // return bool
	{
		foreach (func_get_args() as $object )
		{
			if ( $object == null )
			{
				show_error ( "Invalid Parameter(s)");
				return false;
			}
		}
		return true;
	}

	public function check_null_return_json_error ()
	{
		foreach (func_get_args() as $object )
		{
			if ( $object === null )
			{
				echo $this->json_return_failed();
				exit;
				return false;
			}
		}
		return true;
	}
	public function json_return_failed () 
	{
		return json_encode ( array ( 'status' => false ) );
	}

}


// <editor-fold defaultstate="collapsed" desc="Enumeration Constants">
// </editor-fold>


